package com.fenghongzhang.day006;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

public class Main3Activity extends AppCompatActivity {
    private SlidingTabLayout slidingTabLayout;
    private ViewPager vp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tab_layout);
        vp = (ViewPager) findViewById(R.id.vp);

        List<String> list = new ArrayList<>();
        list.add("电影");
        list.add("新闻");
        list.add("我的");

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new OneFragment());
        fragments.add(new TwoFragment());
        fragments.add(new ThreeFragment());
        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,fragments);
//        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager(), fragments);

//        vp.setOffscreenPageLimit(3);
        vp.setAdapter(myAdapter);
        slidingTabLayout.setViewPager(vp,list.toArray(new String[list.size()]));




    }
}
